﻿using System;
using System.Threading;

namespace CoreLibrary {

    public sealed class GuidUtil {
        
        private static int _uniqueId;

        public static string GuidN() {
            return Guid.NewGuid().ToString("N");
        }

        public static string GuidD() {
            return Guid.NewGuid().ToString("D");
        }

        public static string Base64Guid() {
            var base64 = Convert.ToBase64String(Guid.NewGuid().ToByteArray());
            return base64.Replace("/", "-")
                         .Replace("+", "-")
                         .Replace("&", "-")
                         .Replace("=", string.Empty);
        }
        
        public static int IntGuid(int upperbound) {
            Interlocked.Add(ref _uniqueId, 1);
            return Interlocked.CompareExchange(ref _uniqueId, 0, Int32.MaxValue);
        }

    }

}